<template>
  <div class="app-container">
    <el-form ref="queryFormRef" :inline="true" :model="queryParams" class="demo-form-inline"
      v-hasPermi="['md:customer:query']">
      <el-form-item label="省份" prop="province">
        <el-select v-model="queryParams.province" size="small" filterable clearable placeholder="请选择省份"
          style="width: 100%;">
          <el-option v-for="item in provinceList" :key="item.code" :label="item.name" :value="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model.trim="queryParams.name" :maxlength="50" size="small" placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item label="属性" prop="isImportant">
        <el-select v-model="queryParams.isImportant" size="small" filterable clearable placeholder="请选择属性"
          style="width: 100%;">
          <el-option v-for="item in isImportantList" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目编号" prop="projectNo">
        <el-input v-model.trim="queryParams.projectNo" clearable :maxlength="50" size="small"
          placeholder="请输入项目编号"></el-input>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model.trim="queryParams.projectName" clearable :maxlength="50" size="small"
          placeholder="请输入项目名称"></el-input>
      </el-form-item>
      <el-form-item label="设备名称" prop="deviceName">
        <el-input v-model.trim="queryParams.deviceName" clearable :maxlength="50" size="small"
          placeholder="请输入设备名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" v-hasPermi="['md:customer:query']"
          @click="searchHandler">查询</el-button>
        <el-button icon="el-icon-refresh-right" size="mini" v-hasPermi="['md:customer:query']"
          @click="resetForm('queryFormRef')">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="grid-content bg-purple">
      <el-button plain type="primary" size="mini" icon="el-icon-plus" v-hasPermi="['md:customer:add']"
        @click="openDialog(null)">增加</el-button>
      <!--          <el-button plain type="warning" size="mini" icon="el-icon-download" v-hasPermi="['md:customer:export']" @click="exportHandler">导出</el-button>-->
    </div>

    <el-table ref="tableRef" :data="tableData" v-loading="loading" highlight-current-row max-height="600"
      v-horizontal-scroll="'auto'" @current-change="handleCurrentChange" style="width: 100%;margin-top: 10px;">
      <el-table-column type="index" width="50" align="center" label="序号">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column property="province" label="省份" align="center" width="80" />
      <el-table-column property="clientType" label="客户属性" align="center" width="80" />
      <el-table-column property="name" label="名称" align="center" width="120" />
      <el-table-column property="shortName" label="简称" align="center" width="80" />
      <el-table-column property="isImportant" label="属性" align="center" width="80">
        <template slot-scope="scope">
          <span>{{ getListValue(scope.row.isImportant, isImportantList) }}</span>
        </template>
      </el-table-column>
      <el-table-column property="basis" label="重点依据" align="center" width="180">
        <!--        <template slot-scope="scope">-->
        <!--          <span>{{ getListValue(scope.row.basis, dict.type.sys_key_customer_basis) }}</span>-->
        <!--        </template>-->
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.basis" placement="top">
            <div v-if="scope.row.basis" class=" single-line-ellipsis">{{ scope.row.basis.length > 10 ?
              scope.row.basis.slice(0, 10) + "..." : scope.row.basis }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column property="taxNumber" label="统一社会信用代码" align="center" width="130" />
      <el-table-column property="address" label="地址" align="center" width="120" />
      <el-table-column property="registeredAddress" label="注册地址" align="center" width="120" />
      <el-table-column property="bank" label="开户银行" align="center" width="120" />
      <el-table-column property="bankNumber" label="银行账号" align="center" width="120" />
      <el-table-column property="phone" label="电话号码" align="center" width="120" />
      <el-table-column property="taxRate" label="税率" align="center" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_tax_rate" :value="scope.row.taxRate" />
        </template>
      </el-table-column>
      <el-table-column property="webAddress" label="网址" align="center" width="120" />
      <el-table-column property="legalPerson" label="法定代表人" align="center" width="100" />
      <el-table-column property="type" label="类型" align="center" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_customer_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column property="importantPlan" label="重点建设计划" align="center" width="120">
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.importantPlan" placement="top">
            <div v-if="scope.row.importantPlan" class=" single-line-ellipsis">{{ scope.row.importantPlan.length > 6 ?
              scope.row.importantPlan.slice(0, 6) + "..." : scope.row.importantPlan }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column property="unit" label="举办单位/业务主管单位" align="center" width="180" />
      <el-table-column property="remark" label="备注" align="center" />
      <el-table-column property="createBy" label="创建人" align="center" width="80" />
      <el-table-column property="createTime" label="创建时间" align="center" sortable width="160" />
      <el-table-column label="操作" align="center"
        v-if="$auth.hasPermi('md:school:list') || $auth.hasPermi('md:customer:edit') || $auth.hasPermi('md:customer:remove')">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-view" v-hasPermi="['md:school:list']"
            @click="detailHandler(scope.row)">详情</el-button>
          <el-button type="text" icon="el-icon-edit" v-hasPermi="['md:customer:edit']"
            @click="openDialog(scope.row)">修改</el-button>
          <el-popconfirm confirm-button-text="是" cancel-button-text="否" title="确定删除吗？"
            @confirm="deleteHandler(scope.row)">
            <el-button slot="reference" icon="el-icon-delete" type="text"
              v-hasPermi="['md:customer:remove']" style="margin-left: 10px">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog :title="dialogTitle === 1 ? '新增' : '修改'" :visible.sync="dialogVisible" width="800px" close-on-click-modal
      :fullscreen="device == 'mobile'">
      <el-form :model="form" :rules="rules" ref="formRef" :label-position="device == 'mobile' ? 'top' : 'right'"
        label-width="110px" class="demo-form">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="客户属性" prop="clientType">
              <el-radio-group v-model="form.clientType">
                <el-radio v-for="item in clientTypes" :key="item.value" :label="item.label">{{ item.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="省份" prop="province">
              <el-select v-model="form.province" clearable filterable placeholder="请选择省份" style="width: 100%;">
                <el-option v-for="item in provinceList" :key="item.code" :label="item.name" :value="item.name">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称" prop="name">
              <el-input v-model.trim="form.name" :maxlength="50" placeholder="请输入名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="简称" prop="shortName">
              <el-input v-model.trim="form.shortName" :maxlength="50" placeholder="请输入简称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法定代表人" prop="legalPerson">
              <el-input v-model.trim="form.legalPerson" :maxlength="50" placeholder="请输入法定代表人"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20" v-if="form.clientType === '院校'">
          <el-col :span="12">
            <el-form-item label="类型" prop="type">
              <el-select v-model="form.type" filterable allow-create clearable placeholder="请选择类型" style="width: 100%">
                <el-option v-for="item in dict.type.sys_customer_type" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="重点建设计划" prop="importantPlan">
              <el-select v-model="form.importantPlan" filterable multiple allow-create clearable placeholder="请选择重点建设计划"
                style="width: 100%">
                <el-option v-for="item in dict.type.sys_key_plan" :key="item.value" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="device == 'mobile' ? 24 : 12">
            <el-form-item label="地址" prop="address">
              <el-input v-model.trim="form.address" type="textarea" :maxlength="50" placeholder="请输入地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="device == 'mobile' ? 24 : 12">
            <el-form-item prop="unit" class="cus-form-item" v-if="form.clientType === '院校'">
              <span slot="label">举办单位<br v-if="device !== 'mobile'" />业务主管单位</span>
              <el-input v-model.trim="form.unit" type="textarea" :maxlength="100"
                placeholder="请输入举办单位/业务主管单位"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="属性" prop="isImportant">
              <el-select clearable v-model="form.isImportant" placeholder="请选择属性" style="width: 100%">
                <el-option v-for="item in isImportantList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="重点依据" prop="basis" v-if="form.isImportant === 1">
              <el-select v-model="form.basis" filterable clearable multiple allow-create placeholder="请选择重点依据"
                style="width: 100%">
                <el-option v-for="item in dict.type.sys_key_customer_basis" :key="item.value" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="device == 'mobile' ? 24 : 12">
            <el-form-item class="cus-form-item" label="统一社会信用代码" prop="taxNumber">
              <span slot="label">统一社会<br v-if="device !== 'mobile'" />信用代码</span>
              <el-input v-model.trim="form.taxNumber" type="textarea" :maxlength="50" placeholder="请输入统一社会信用代码"
                :autosize="{ minRows: 2 }" />
            </el-form-item>
          </el-col>
          <el-col :span="device == 'mobile' ? 24 : 12">
            <el-form-item label="注册地址" prop="registeredAddress">
              <el-input v-model.trim="form.registeredAddress" type="textarea" :maxlength="50" placeholder="请输入注册地址" :autosize="{ minRows: 2 }" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="开户银行" prop="bank">
              <el-input v-model.trim="form.bank" :maxlength="50" placeholder="请输入开户银行" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行账号" prop="bankNumber">
              <el-input v-model.trim="form.bankNumber" :maxlength="50" placeholder="请输入银行账号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="电话号码" prop="phone">
              <el-input v-model.trim="form.phone" :maxlength="20" placeholder="请输入电话号码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税率" prop="taxRate">
              <el-select v-model="form.taxRate" allow-create clearable filterable placeholder="请选择税率"
                style="width: 100%;">
                <el-option v-for="item in dict.type.sys_tax_rate" :key="item.value" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="显示排序" prop="orderNum">
          <el-input-number v-model.trim="form.orderNum" :min="0" :step="1" step-strictly style="width: 100%;" />
        </el-form-item>
        <el-form-item label="网址" prop="webAddress">
          <el-input v-model.trim="form.webAddress" :maxlength="50" placeholder="请输入网址, 没有填无" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model.trim="form.remark" type="textarea" :maxlength="200" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('formRef')">提交</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { addDataApi, deleteDataApi, getDataListApi, updateDataApi } from "@/api/crm/md/customer";
import ProvinceData from '@/views/crm/data/province.json'
import { getUserProfile } from "@/api/system/user";
import School from "@/views/crm/md/school/index.vue";
import SchoolProduct from "@/views/crm/md/school/components/product.vue";
import { findItemsNotInOrigin } from "@/utils";
import { addData } from "@/api/system/dict/data";
import DictData from "@/utils/dict/DictData";
import { refreshCache } from "@/api/system/dict/type";
import { mapGetters } from 'vuex'

export default {
  name: 'CustomerView',
  components: { SchoolProduct, School },
  dicts: ['sys_key_customer_basis', 'sys_customer_type', 'sys_key_plan', 'sys_tax_rate'],
  data() {
    return {
      // 记录上一次打开弹窗是修改or增加
      // null 增加
      // 非null 修改
      formId: null,
      // 加载动画
      loading: true,
      // 省份数据
      provinceList: [],
      // 弹框标题 1是增加 其他是修改
      dialogTitle: 1,
      // 弹框显示
      dialogVisible: false,
      // 客户属性
      clientTypes: [
        {
          value: '院校',
          label: '院校'
        },
        {
          value: '企业',
          label: '企业'
        }
      ],
      // 新增和修改参数
      form: {
        orderNum: null, // 显示排序
        webAddress: "", // 网址
        taxRate: "", // 税率
        clientType: "院校", // 企业类型
        shortName: "", // 简称
        address: "", // 地址
        basis: [], // 依据
        createBy: "", // 用户 *
        id: null, // id
        isImportant: 0, // 是否重点客户 0是普通 1是重点 *
        name: "", // 学校名 *
        province: "", // 省份 *
        remark: "", // 备注
        updateBy: "", // 更新人
        legalPerson: "", // 法人
        type: null, // 类型
        importantPlan: [], // 重点计划
        unit: "", // 举办单位/业务主管单位
        taxNumber: "", // 统一社会信用代码
        registeredAddress: "", // 注册地址
        phone: "", // 电话
        bank: "", // 开户银行
        bankNumber: "", // 银行账号
      },
      // 重点客户下拉数据
      isImportantList: [
        {
          value: 0,
          label: '普通客户'
        },
        {
          value: 1,
          label: '重点客户'
        }
      ],
      // 表单的校验规则
      rules: {
        unit: [
          { required: true, message: '请填写举办单位/业务主管单位', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请填写地址', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请填写名称', trigger: 'blur' }
        ],
        taxNumber: [
          { required: true, message: '请填写统一社会信用代码', trigger: 'blur' }
        ],
        shortName: [
          { required: true, message: '请填写简称', trigger: 'blur' }
        ],
        webAddress: [
          { required: true, message: '请填写网址', trigger: 'blur' }
        ],
        legalPerson: [
          { required: true, message: '请填写法定代表人', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择类型', trigger: 'change' }
        ],
        importantPlan: [
          { required: true, message: '请选择重点建设计划', trigger: 'change' }
        ],
        isImportant: [
          { required: true, message: '请选择属性', trigger: 'change' }
        ],
        // taxRate: [
        //   { required: true, message: '请选择税率', trigger: 'change' }
        // ],
        basis: [
          { required: true, message: '请选择依据', trigger: 'change' }
        ],
        province: [
          { required: true, message: '请选择省份', trigger: 'change' }
        ],
      },
      // 表格数据
      tableData: [],
      // 总数条数
      total: 0,
      // 查询参数
      queryParams: {
        flag: true,
        projectNo: "", // 项目编号
        deviceName: "", // 设备名称
        projectName: "",
        isImportant: null, // 是否重点客户 0是普通 1是重点 *
        name: "", // 学校名 *
        province: "", // 省份 *
        pageNum: 1,
        pageSize: 10,
      },
      // 用户信息
      user: {},
      roleGroup: {},
      postGroup: {},
      customerInfo: {
        id: null
      }
    }
  },
  computed: {
    ...mapGetters([
      'device'
    ]),
  },
  watch: {
    'form.isImportant': {
      handler(newV) {
        if (newV !== 1) {
          this.form.basis = []
        }
      }
    },
  },
  created() {
    this.provinceList = ProvinceData
    this.getList()
    this.getUserinfo()
  },
  activated() {
    this.getList()
  },
  methods: {
    // 选择类型的回调
    async selectTypeChange(val) {
      if (!val.length) return false
      const dictName = "sys_customer_type"
      const oList = this.dict.type[dictName].map(i => i.value)
      const list = findItemsNotInOrigin([val], oList)

      /*
      * dictLabel: "1"
      * dictSort: 1111
      * dictType: "sys_key_plan"
      * dictValue: "1"
      * listClass: "default"
      * status: "0"
      * */
      if (!list.length) return false
      const payload = {
        dictLabel: list[0],
        dictSort: this.dict.type[dictName].length,
        dictType: dictName,
        dictValue: list[0],
        listClass: "default",
        status: "0"
      }

      // 增加字典数据
      await addData(payload)

      // 重新获取字典数据
      const res = await this.getDicts(dictName)
      if (res.code === 200) {
        this.dict.type[dictName] = (res.data ?? []).map((i) => {
          return new DictData(i.dictLabel, i.dictValue, i)
        })
      }
      await refreshCache()
    },
    // 选择重点依据的回调
    async selectBasisChange(val) {
      if (!val.length) return false
      const dictName = "sys_key_customer_basis"
      const oList = this.dict.type[dictName].map(i => i.value)
      const list = findItemsNotInOrigin(val, oList)

      /*
      * dictLabel: "1"
      * dictSort: 1111
      * dictType: "sys_key_plan"
      * dictValue: "1"
      * listClass: "default"
      * status: "0"
      * */
      if (!list.length) return false
      const payload = {
        dictLabel: list[0],
        dictSort: this.dict.type[dictName].length,
        dictType: dictName,
        dictValue: list[0],
        listClass: "default",
        status: "0"
      }

      // 增加字典数据
      await addData(payload)

      // 重新获取字典数据
      const res = await this.getDicts(dictName)
      if (res.code === 200) {
        this.dict.type[dictName] = (res.data ?? []).map((i) => {
          return new DictData(i.dictLabel, i.dictValue, i)
        })
      }

      await refreshCache()
    },
    // 选择重点建设计划的回调
    async selectChange(val) {
      if (!val.length) return false
      const dictName = "sys_key_plan"
      const oList = this.dict.type[dictName].map(i => i.value)
      const list = findItemsNotInOrigin(val, oList)

      /*
      * dictLabel: "1"
      * dictSort: 1111
      * dictType: "sys_key_plan"
      * dictValue: "1"
      * listClass: "default"
      * status: "0"
      * */
      if (!list.length) return false
      const payload = {
        dictLabel: list[0],
        dictSort: this.dict.type[dictName].length,
        dictType: dictName,
        dictValue: list[0],
        listClass: "default",
        status: "0"
      }

      // 增加字典数据
      await addData(payload)

      // 重新获取字典数据
      const res = await this.getDicts(dictName)
      if (res.code === 200) {
        this.dict.type[dictName] = (res.data ?? []).map((i) => {
          return new DictData(i.dictLabel, i.dictValue, i)
        })
      }

      await refreshCache()
    },
    handleCurrentChange(row) {
      this.customerInfo = { ...row }
    },
    // 跳转客户详情
    detailHandler(row) {
      this.$router.push({ name: 'CustomerDetail', query: { customerId: row.id } })
    },
    // 选择重点的回调
    changePropertyHandler(val) {
      if (val === 0) {
        this.form.basis = []
      }
    },
    // 获取根据list中的value返回label
    getListValue(data, list, value = 'value') {
      let label = ''
      list.map((item) => {
        if (+item[value] === +data) {
          label = item.label
        }
      })
      return label
    },
    // 获取用户信息
    getUserinfo() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
    // 获取数据
    async getList() {
      this.loading = true
      const res = await getDataListApi({
        ...this.queryParams,
        userId: this.$store.state.user.id,
        deptId: this.$store.state.user.deptId,
      })
      if (res.code === 200) {
        this.tableData = res.rows
        this.total = res.total
      }
      this.loading = false
    },
    // 搜索的回调
    searchHandler() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 删除的回调
    async deleteHandler(row) {
      const res = await deleteDataApi({
        id: row.id
      })
      if (res.code === 200) {
        this.$message({
          message: res.msg,
          type: 'success'
        });
        this.getList()
        this.dialogVisible = false
      } else {
        this.$message({
          message: res.msg,
          type: 'error'
        });
      }
    },
    // 打开弹窗
    openDialog(row) {
      if (row) {
        this.formId = row.id
        this.form = {
          ...row,
          basis: (row.basis?.split(',') ?? []).filter(i => i),
          importantPlan: row.importantPlan?.split(',') ?? []
        }
        this.dialogTitle = 2
      } else {
        if (this.formId) {
          this.form = { ...this.$options.data().form }
        }
        this.formId = null
        this.dialogTitle = 1
      }
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs['formRef'].clearValidate();
        // this.resetForm('formRef')
      })
    },
    // 导出的回调
    async exportHandler() {
      this.download('crm/client/export', {
        ...this.queryParams,
        userId: this.user.userId,
        deptId: this.user.deptId,
      }, `customers_${new Date().getTime()}.xlsx`)
    },
    // 表单提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.dialogTitle === 1) {
            this.addDataHandler()
          } else {
            this.updateDataHandler()
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 增加数据的回调
    async addDataHandler() {
      const payload = {
        ...this.form,
        basis: this.form.basis.join(','),
        importantPlan: this.form.importantPlan.join(','),
        createBy: this.user.nickName,
        updateBy: this.user.nickName,
        userId: this.user.userId,
      }
      const res = await addDataApi(payload)
      if (res.code === 200) {
        this.$message({
          message: res.msg,
          type: 'success'
        });
        this.getList()
        this.formId = -1
        this.dialogVisible = false
        this.$refs.formRef.resetFields()
      } else {
        this.$message({
          message: res.msg,
          type: 'error'
        });
      }
    },
    // 修改数据的回调
    async updateDataHandler() {
      const payload = {
        ...this.form,
        basis: this.form.basis.join(','),
        importantPlan: this.form.importantPlan.join(','),
        updateBy: this.user.nickName,
      }
      const res = await updateDataApi(payload)
      if (res.code === 200) {
        this.$message({
          message: res.msg,
          type: 'success'
        });
        this.getList()
        this.dialogVisible = false
      } else {
        this.$message({
          message: res.msg,
          type: 'error'
        });
      }
    },
    // 重置表单
    resetForm(formName) {
      if (this.$refs[formName]) {
        this.$refs[formName].resetFields();
      }
    }
  },
}
</script>
<style scoped lang="scss">
.cus-form-item {
  &::v-deep .el-form-item__label {
    line-height: 26px !important;
  }
}
</style>
